// import Cookies from 'js-cookie'
import { SSAaesEncrypt } from '@/utils/crypto'
import axios from "axios";
const TokenKey = '__ADMIN__'

export function getToken() {
  // return Cookies.get(TokenKey)
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token) {
  sessionStorage.setItem(TokenKey, token)
  // return Cookies.set(TokenKey, token)
}

export function removeToken() {
  // return Cookies.remove(TokenKey)
  sessionStorage.removeItem(TokenKey)
}


export function GetSSAToken() {
  var userId = "";
  //设置长度，这里看需求，我这里设置了4
  var codeLength = 26;
  //设置随机字符
  var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  //循环codeLength 我设置的4就是循环4次
  for (var i = 0; i < codeLength; i++) {
    //设置随机数范围,这设置为0 ~ 36
    var index = Math.floor(Math.random() * 9);
    //字符串拼接 将每次随机的字符 进行拼接
    userId += random[index];
  }
  sessionStorage.setItem('SSA_USERID', userId)
  return axios
    .post("https://spaq.suzhou.gov.cn/ssa-pc-api/code/saveCode", {
      id: userId
    }, {
      headers: { timestamp: SSAaesEncrypt(Date.parse(new Date()), '53af4e0914f92ac0') },
    })
}
